package net.discard.handler;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import org.springframework.stereotype.Service;
import xyz.erupt.annotation.fun.AttachmentProxy;

import java.io.InputStream;

/**
 * @Author: Discard
 * @Date: 2021/2/19 10:02 上午
 */
@Service
public class OssHandler implements AttachmentProxy {

    @Override
    public void upLoad(InputStream inputStream, String path) {
        String endpoint = "oss-cn-beijing.aliyuncs.com";
        String accessKeyId = "ShCuC55lnNktEPbZ";
        String accessKeySecret = "M9BdAG7jeHxxlnHcBhhZiTMOysumMb";
        OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
//        String fileName = path.split("/")[1];
        ossClient.putObject("jy-image-discard", "activity-image" + path, inputStream);
        ossClient.shutdown();
    }

    @Override
    public String fileDomain() {
        return "https://jy-image-discard.oss-cn-beijing.aliyuncs.com/activity-image";
    }

    @Override
    public boolean isLocalSave() {
        return false;
    }
}
